package com.bilibili.juc.cf.one;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/*
cfA.thenComposeAsync(cfB)  thenComposeAsync方法会将cfA的结果传递给cfB
 */
public class ThenCompose2Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {


        //第二个异步任务
        ExecutorService executor = Executors.newSingleThreadExecutor();
        CompletableFuture<Integer> future = CompletableFuture
                .supplyAsync(() -> 10, executor)
                .thenComposeAsync(data -> {
                    System.out.println("获得第一个cf的结果: " + data);
                    return CompletableFuture.supplyAsync(()-> data+20); //使用第一个任务作为返回
                }, executor);
        System.out.println("最后的结果：" + future.join());
        executor.shutdown();

    }
}
/*
获得第一个cf的结果: 10
最后的结果：30
 */
